package com.shuai.baibi.manager;

import com.shuai.baibi.service.AITemplateService;
import com.shuai.baibi.service.XunFeiBigModelService;
import lombok.extern.slf4j.Slf4j;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.net.MalformedURLException;
import java.net.URISyntaxException;

@Service
@Slf4j
public class XunFeiAPIManager {

    @Autowired
    private AITemplateService aiTemplateService;
    private final String modelName = "spark-ai";
    private String prompt;

    public String ask(String content) {
        if (prompt == null) {
            prompt = aiTemplateService.getPromptByModelName(modelName).getPrompt();
        }
        XunFeiBigModelService xunFeiAIService = new XunFeiBigModelService();
        try {
            return xunFeiAIService.ask(content + prompt);
        } catch (MalformedURLException | URISyntaxException e) {
            log.error("AI模型配置错误：" + e.getMessage());
            throw new RuntimeException(e);
        }
    }
}
